package com.shijie.newvideo;

import android.content.Context;
import android.os.Bundle;
import android.util.Log;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.shijie.newvideo.base.BaseRefreshRecyclerViewFragment;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * 我的订单
 */
public class OrderListFragment extends BaseRefreshRecyclerViewFragment<VodBean.ListDTO> {


    private String productType;

    public static Fragment newInstance(String productType) {
        Fragment fragment = new OrderListFragment();
        Bundle bundle = new Bundle();
        bundle.putString("productType", productType);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (getArguments() != null) {
            Bundle bundle = getArguments();
            productType = bundle.getString("productType");
        }
    }

    @Override
    protected void initUI() {
        super.initUI();
        if (mRecyclerView != null) {
            mRecyclerView.setBackgroundColor(getResources().getColor(R.color.color_f8f8f8));
        }
    }

    @Override
    protected RecyclerView.LayoutManager createLayoutManager(Context context) {
        return new GridLayoutManager(context, 2);
    }

    @Override
    protected RecyclerView.ItemDecoration createItemDecoration(Context context) {
        return new SpaceItemDecoration(DeviceInfoUtil.dp2px(context, 12), 0, false, SpaceItemDecoration.GRIDLAYOUT);
    }

    @Override
    protected RecyclerView.Adapter createAdapter(List<VodBean.ListDTO> list) {
        return new VodListAdapter(context, list);
    }

    @Override
    protected void getListData(final int pageNo) {
        Call<VodBean> call = RetrofitClient.getApiService().getKanshipinglist("list", null);
        call.enqueue(new Callback<VodBean>() {
            @Override
            public void onResponse(Call<VodBean> call, Response<VodBean> response) {
                if (response.isSuccessful()) {
                    VodBean vodBean = response.body();
                    Log.e("Network User: ", vodBean.toString());
                    onRequestSuccess(vodBean.getList(), "没有数据", R.drawable.kb_wuneirong);
                } else {
                    Log.e("Network Error: ", response.message());
                }
            }

            @Override
            public void onFailure(Call<VodBean> call, Throwable t) {
                Log.e("Network Error: ", t.getMessage());
            }
        });


//        RequestManager.setSchedulers(RequestManager.getInstanceRx().getServiceRx().myOrderList(productType, pageNo))
//                .subscribe(new NormalSubscriber<OrderBeen>(context) {
//                    @Override
//                    public void onSuccess(OrderBeen data) {
//                        super.onSuccess(data);
//                        ArrayList<OrderListBeen> list = data.getList();
//                        onRequestSuccess(list, context.getString(R.string.暂无相关订单数据), R.drawable.kb_wuneirong);
//
//                    }
//
//                    @Override
//                    public void onError(Throwable e) {
//                        super.onError(e);
//                        onRequestFail(e, context.getString(R.string.内容加载失败_请检查网络), R.drawable.kb_wuwangluo);
//                    }
//                });
    }

}
